// 0001
module.exports = {
  buyIfOnlyPingByReason1h () {
    if (
      this.analysisInfo1h.lastKdjDownDays >= 24 &&
      this.analysisInfo1h.kdjDiff > 0 &&
      this.analysisInfo1h.kdjUpDays <= 2 &&
      this.analysisInfo1h.ema5 < this.analysisInfo1h.ema20 &&
      this.tradeTime15mCycle === 4
    ) {
      this.setBuyByReason('buyIfOnlyPingByReason-0001', {
        level: 100,
        rate: 0.5,
        useRawPosition: true
      })
    }
  },
  buyIfOnlyPingByReasonMarketBigDown () {
    if (
      this.marketInfo.k15mNetChangeRatio < -20 &&
      this.analysisInfo15m.ema5 < this.analysisInfo15m.ema20
    ) {
      // 止盈设置为125
      if (this.analysisInfo15m.netChangeRatio <= -35) {
        this.setBuyByReason('buyIfOnlyPingByReason-mbd-0001', {
          // 跌幅越大，优先级越高
          level: 1000 + Math.abs(this.analysisInfo15m.netChangeRatio),
          rate: 1,
          useRawPosition: true,
          leverage: 3
        })
      }
    }
    if (
      this.marketInfo.k15mNetChangeRatio < -25 &&
      this.analysisInfo15m.ema5 < this.analysisInfo15m.ema20
    ) {
      // 止盈设置为125
      // this.analysisInfo15m.netChangeRatio <= (this.marketInfo.k15mNetChangeRatio * 1.5)
      if (this.analysisInfo15m.netChangeRatio <= (this.marketInfo.k15mNetChangeRatio * 1.5)) {
        this.setBuyByReason('buyIfOnlyPingByReason-mbd-0002', {
          // 跌幅越大，优先级越高
          level: 1000 + Math.abs(this.analysisInfo15m.netChangeRatio),
          rate: 1,
          useRawPosition: true,
          useMaxPosition: true,
          leverage: 3
        })
      }
    }
    if (
      this.marketInfo.k15mNetChangeRatio < -30 &&
      this.analysisInfo15m.ema5 < this.analysisInfo15m.ema20
    ) {
      // 这时候跌幅小于1.2整体的不能买入，最好是就买1.5倍的
      // this.analysisInfo15m.netChangeRatio <= (this.marketInfo.k15mNetChangeRatio * 1.5)
      if (this.analysisInfo15m.netChangeRatio <= -35) {
        // 止盈设置为150
        this.setBuyByReason('buyIfOnlyPingByReason-mbd-0003', {
          // 跌幅越大，优先级越高
          level: 1000 + Math.abs(this.analysisInfo15m.netChangeRatio),
          rate: 1,
          useRawPosition: true,
          useMaxPosition: true,
          leverage: 3
        })
      }
    }
  },
  buyIfOnlyPingByReason () {
    this.buyIfOnlyPingByReason1h()
    // const ifCanBottomFishing = (
    //   (this.analysisInfo15m.netChangeRatio >= -65 && this.btbItem.price_change_percent > -50) ||
    //   // 整体跌幅大，或者是-35：2025/10/11 5:30
    //   this.marketInfo.k15mNetChangeRatio < -10
    // )
    const ifCanBottomFishing = true
    if (
      this.analysisInfo1d.isLongDuo &&
      (this.is4hLastTime && this.analysisInfo4h.netChangeRatio <= -25) &&
      this.analysisInfo1h.netChangeRatio <= -20 &&
      this.analysisInfo15m.netChangeRatio <= -20 &&
      this.analysisInfo15m.netChangeRatioDownDays >= 2 &&
      ifCanBottomFishing
    ) {
      this.setBuyByReason('buyIfOnlyPingByReason-5', {
        level: 100,
        rate: 1,
        useRawPosition: true,
        leverage: 3
      })
    }
    if (
      this.analysisInfo15m.netChangeRatio <= -35 &&
      this.analysisInfo15m.ema5 < this.analysisInfo15m.ema20 &&
      ifCanBottomFishing
    ) {
      if (
        !this.hasDuoPosition ||
        this.symbolAccount.position < 0.3
      ) {
        this.setBuyByReason('buyIfOnlyPingByReason-2', {
          level: 100,
          rate: 1,
          useRawPosition: true,
          leverage: 3
        })
      }
    }
    if (
      this.analysisInfo15m.netChangeRatio <= -50 &&
      this.analysisInfo15m.ema5 < this.analysisInfo15m.ema20 &&
      ifCanBottomFishing
    ) {
      this.setBuyByReason('buyIfOnlyPingByReason-3', {
        level: 100,
        rate: 1,
        useRawPosition: true,
        leverage: 3
      })
    }
    // 优先级最高
    this.buyIfOnlyPingByReasonMarketBigDown()
  },
  // 回踩
  buyIfStepBack () {
    if (this.marketInfo && this.marketInfo.kdj4hGood) {
      if (
        this.analysisInfo4h.kdjDiff > 0 &&
        (this.marketInfo.kdj15mBad && this.marketInfo.macd15mBad) &&
        !(this.marketInfo.ema4hBad || this.marketInfo.macd4hBad) &&
        this.marketFlagInfo.ifMarket15mMacdEmaAllBad &&
        (this.marketInfo.ema1hGood || this.marketInfo.macd1hGood)
      ) {
        if (
          this.analysisInfo1h.macd > 0 &&
          this.analysisInfo1h.ema5A10Days >= 3
        ) {
          if (
            (this.analysisInfo15m.ema5 < this.analysisInfo15m.ema20) &&
            // kdj开始掉头
            this.analysisInfo15m.isKdjIncrease &&
            this.analysisInfo15m.ema5B20Days <= 6 &&
            this.analysisInfo15m.lastEma5A20Days >= 16 &&
            this.analysisInfo15m.lastEma5A20Rate >= 6
          ) {
            // 回踩这个很奇怪，中间都是亏钱，但拿到卖出的时候，又都是挣钱的
            this.setBuy('buyIfStepBack-1', {
              rate: 0.5,
              coverPositionConfig: 0.66
            })
            this.ifOnlyPingDuoByReason = true
            // this.buySellRawTotalWalletBalance = true
          }
        }
      }
    }
    if (
      this.analysisInfo1h.kdjDiff < 0 &&
      this.analysisInfo4h.kdjDiff > 0 &&
      this.analysisInfo1h.lastKdjUpKeepInfo.maxHighRate >= 70 &&
      this.analysisInfoFlag1h.getRecentDaysHasBigUpDay(this.analysisInfo1h.lastKdjUpDays, 35) &&
      this.analysisInfo1h.low < this.analysisInfo1h.ema10 &&
      this.analysisInfo1h.macd > 0 &&
      this.analysisInfo1h.ema5A10A20Days >= 1 &&
      this.tradeTime15mCycle === 4 &&
      (this.marketInfo.kdj4hGood || this.marketInfo.macd4hGood)
    ) {
      this.setBuy('buyIfStepBack-2', {
        rate: 0.5,
        coverPositionConfig: 0.66
      })
      this.ifOnlyPingDuoByReason = true
      // this.buySellRawTotalWalletBalance = true
    }
  }
}
